#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_flask_get.py
# author:张世航
# datetime:2024/12/3 19:10
# software: PyCharm
"""
this is function  description 
"""
# import module your need

from flask import Flask,request
import json

app = Flask(__name__)

@app.route('/api', methods=['GET'])
def get_api():
    res = {'code': 200, 'message': 'successful!'}  # 构造接口返回的数据
    return json.dumps(res, ensure_ascii=False)  # 将数据转换为json格式并返回


@app.route('/test', methods=['GET'])
def test():
    # 定义返回的数据的默认值
    return_dict = {'code': '200', 'message': 'successful!', 'data': None}
    # 判断入参是否为空
    if len(request.args) == 0:
        return_dict['code'] = '5004'  # 自定义状态码
        return_dict['message'] = '请求参数为空'
        return json.dumps(return_dict, ensure_ascii=False)
    # 获取传入的params参数
    params = request.args.to_dict()
    name = params.get('name')
    age = params.get('age')
    return_dict['data'] = {
        'name': name,
        'age': age
    }
    return json.dumps(return_dict, ensure_ascii=False)




if __name__ == '__main__':
    app.run(port=5000, debug=True)
